/*
 *  CEMenu.cpp
 *  LID Library
 *
 *  Created by Alexander Trutchenko on 09/11/11.
 *  Copyright 2011 League of Independent Developers. All rights reserved.
 *
 */

#include "cocos2dx_extentions/controls/CEMenu.h"


using namespace cocos2d;

namespace cocosext {

/////////////////////////////////////////////////////
//
/** CEMenu 
* 
*/
/////////////////////////////////////////////////////

CEMenu* CEMenu::node(int touchPriority)
{
    return menuWithItem(touchPriority, NULL);
}

CEMenu* CEMenu::menuWithItem(int touchPriority, CCMenuItem* item)
{
	return menuWithItems(touchPriority, item, NULL);
}

CEMenu * CEMenu::menuWithItems(int touchPriority, CCMenuItem* item, ...)
{
	va_list args;
	va_start(args,item);
	CEMenu *pRet = new CEMenu(touchPriority);
	if (pRet && pRet->initWithItems(item, args))
	{
		pRet->autorelease();
		va_end(args);
		return pRet;
	}
	va_end(args);
	CC_SAFE_DELETE(pRet)
	return NULL;
}

/////////////////////////////////////////////////////
//Cocos2d interface

void CEMenu::registerWithTouchDispatcher()
{
	CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, _touchPriority, true);
}

void CEMenu::setTouchPriority(int newPriority)
{
	if (_touchPriority == newPriority)
		return;
	_touchPriority = newPriority;
	if (CCTouchDispatcher::sharedDispatcher()->findHandler(this) != NULL)
		CCTouchDispatcher::sharedDispatcher()->setPriority(_touchPriority, this);

}

}; // end namespace cocosext

